
import { getDict } from '@/utils/index'
import { transferLabelAndValue } from '@/utils/pre-sale'
import {
    getAllBrand,
    getSeries,
    getModelTimeType,
    getModelRank,
} from '@/api/after-sale/systemManage/carModel'
const dict = getDict([
    '跟进方式',
    '客户级别',
    '跟进方式',
    '跟进结果',
    '来源渠道',
    '性别',
])
const gjjg = dict['跟进结果'].filter(item => item.type !== 'store')
function formData(data, leaf = false) {
    let nodes = []
    if (Array.isArray(data) && data.length > 0) {
        nodes = data.map((e) => {
            let t =
                e instanceof Object &&
                'id' in e &&
                ('name' in e || 'modelName' in e)
            return (e = {
                value: t ? e.id : e,
                label: t ? (e.name ? e.name : e.modelName) : e,
                leaf,
            })
        })
    }
    return nodes
}


export const rulesForm = [
    {
        "type": "cascader", "field": "carModelId", "value": [],
        title: "意向车型",
        props: {
            placeholder: "意向车型",
            props: {
                lazy: true,
                value: 'value',
                label: 'label',
                lazyLoad(node, resolve) {
                    let { level, root, value, path } = node
                    if (level == 0 && root) {
                        getAllBrand().then((res) => {
                            let { data, success } = res
                            resolve(formData(success ? res.data : []))
                        })
                    } else if (level == 1) {
                        getSeries(value).then((res) => {
                            let { data, success } = res
                            resolve(formData(success ? res.data : []))
                        })
                    } else if (level == 2) {
                        getModelTimeType(path[0], path[1]).then((res) => {
                            let { data, success } = res
                            resolve(formData(success ? res.data : []))
                        })
                    } else if (level == 3) {
                        getModelRank(path[0], path[1], path[2]).then((res) => {
                            let { data, success } = res
                            resolve(formData(success ? res.data : [], true))
                        })
                    }
                },
            },
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",
        validate: [{ required: true, message: '请输入意向车型', trigger: ['blur', 'change'], },]
    },
    {
        "type": "inputNumber", "field": "budget", "value": 0,
        title: "购车预算",
        props: {
            placeholder: "购车预算",
            min: 0,
            controlsPosition: "right"
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",
        validate: [{ required: true, message: '请输入购车预算', trigger: ['blur', 'change'], },]

    },
    {
        "type": "input", "field": "userName", "value": "",
        title: "客户姓名",
        props: {
            placeholder: "客户姓名",
        },
        col: {
            span: 12,
            labelWidth: '120px'
        },
        class: "w-100",
        validate: [{ required: true, message: '请输入客户姓名', trigger: ['blur', 'change'], },]

    },
    {
        "type": "select", "field": "level", "value": "",
        title: "客户级别",
        props: {
            placeholder: "客户级别",
        },
        col: {

            span: 12, labelWidth: '120px'
        },
        options: transferLabelAndValue(dict['客户级别']),
        class: "w-100",
        validate: [{ required: true, message: '请选择客户级别', trigger: ['blur', 'change'], },]

    },
    {
        "type": "select", "field": "mode", "value": "",
        title: "跟进方式",
        props: {
            placeholder: "跟进方式",
        },
        col: {

            span: 12,
            labelWidth: '120px'
        },
        options: transferLabelAndValue(dict['跟进方式']),
        class: "w-100",
        validate: [{ required: true, message: '请选择跟进方式', trigger: ['blur', 'change'], },]

    },
    {
        "type": "select", "field": "result", "value": '',
        title: "跟进结果",
        props: {
            placeholder: "跟进结果",

        },
        col: {

            span: 12, labelWidth: '120px'
        },
        options: transferLabelAndValue(gjjg),
        class: "w-100",
        validate: [{ required: true, message: '请选择跟进结果', trigger: ['blur', 'change'], },]

    },
    {
        "type": "select", "field": "sourceId", "value": '',
        title: "来源渠道",
        props: {
            placeholder: "来源渠道",

        },
        col: {

            span: 12, labelWidth: '120px'
        },
        options: transferLabelAndValue(dict['来源渠道']),
        class: "w-100",
        validate: [{ required: true, message: '请选择来源渠道', trigger: ['blur', 'change'], },]

    },
    {
        "type": "select", "field": "sex", "value": '',
        title: "性别",
        props: {
            placeholder: "性别",

        },
        col: {

            span: 12, labelWidth: '120px'
        },
        options: transferLabelAndValue(dict['性别']),
        class: "w-100",
        validate: [{ required: true, message: '请选择性别', trigger: ['blur', 'change'], },]

    },
    {
        "type": "inputNumber", "field": "age", "value": 0,
        title: "年龄",
        props: {
            placeholder: "年龄",
            type: 'number',
            max: 99,
            min: 0,
            controlsPosition: "right"
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",
        validate: [{ required: true, message: '请输入年龄', trigger: ['blur', 'change'], },]

    },
    {
        "type": "input", "field": "address", "value": "",
        title: "家庭住址",
        props: {
            placeholder: "家庭住址",
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",

    },
    {
        "type": "input", "field": "identity", "value": "",
        title: "身份证号码",
        props: {
            placeholder: "身份证号码",
            maxlength: 18
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",

    },
    {
        "type": "input", "field": "buyUse", "value": "",
        title: "购买用途",
        props: {
            placeholder: "购买用途",
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",

    },
    {
        "type": "inputNumber", "field": "buyNum", "value": 0,
        title: "购买次数",
        props: {
            placeholder: "购买次数",
            min: 0,
            controlsPosition: "right"
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",

    },
    {
        "type": "DatePicker", "field": "returnTime", "value": "",
        title: "下次回访时间",
        props: {
            "type": "datetime",
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            placeholder: "下次回访时间",
        },
        col: {
            span: 12, labelWidth: '120px'
        },
        class: "w-100",

    },
    {
        "type": "input", "field": "remark", "value": "",
        title: "备注",
        props: {
            placeholder: "备注",
            type: 'textarea',
            rows: 3
        },
        col: {
            span: 24,
            labelWidth: '120px'
        },
        class: "w-100",

    },

]